layui.define([ 'layedit', 'admin','inputTag', 'view','validate','selfUtils', 'laydate', 'form', 'table','laytpl'], function (exports) {

    var $ = layui.jquery
        ,layedit = layui.layedit
        ,form = layui.form
        ,laytpl = layui.laytpl
        ,inputTag = layui.inputTag
        ,admin = layui.admin
        ,brand = layui.selfUtils
        ,layer = layui.layer
        ,view = layui.view
        ,table = layui.table
        ,laydate = layui.laydate
        ,router = layui.router();

    form.render();

    var contentIndex = layedit.build('content', {
        tool: ['strong', 'italic', 'underline', 'del', '|', 'left', 'center', 'right'],
        height: $("#LAY-theme-sop-add").height()*0.5,
        width: $("#soptitle").width()
    });

    form.on('submit(submitSop)', function(data){
        // 获取富文本的内容
        var content = layedit.getContent(contentIndex);
        data.field['content'] = content;
        let triggerWord = data.field['triggerWord'];
        data.field['triggerWord'] = triggerWord.replaceAll("[","").replaceAll("]","").replaceAll("\"","")
        let handler = data.field['handler'];
        data.field['handler'] = handler.replaceAll("[","").replaceAll("]","").replaceAll("\"","");
        brand.post("/sop/addSop",data.field,function (res) {
            if(res.status != '200'){
                // 失败
                brand.alert.error(res.message);
                return false;
            }
            brand.alert.success(res.message, {
                end: function () {
                    $("#refreshBtn").click();
                }
            });
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    //对外暴露的接口
    exports('sop/sopAdd', {});

});


